<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=basePath%>/js/jquery-1.9.0.js"></script>
<script>
	$(function(){
		var href=window.location.href;
		var arrhref=href.split("?proId=");
		var proId=arrhref[1];
		var proLeft;
		$("#buyNum").val("1份");
		/**************加载页面**************/
		$.ajax({
	         type: "POST",
	         url:"<%=basePath%>invest/getProKinds?proId=" + proId,
			 dataType : 'JSON',
			 success : function(data) {
				 bindData(data);
			 }
		});
		function bindData(data) {
			$("#proName").val(data.pro_name);
			$("#wantBuy").val(data.pro_price);
			$("#currentProfit").val(data.year_profit + "%");
			$("#wantBuy").val(data.pro_price);
			$("#investTime").val(data.pro_cycle + "天");
			$("#leftNum").val(data.pro_left + "份");
			$("#replyStyle").val(data.reply_type);
			proLeft = data.pro_left;
			bindClick();
		}

		/**************绑定点击事件************/
		function bindClick() {
			var proPrice = $("#wantBuy").val();
			var num = $("#buyNum").val().replace(/[^0-9]/ig, "");
			$("#reduce").click(function() {
				var price = $("#wantBuy").val();
				if (price > proPrice) {
					price = parseInt(price);
					proPrice = parseInt(proPrice);
					$("#wantBuy").val(price - proPrice);
					if (num > 1) {
						num = parseInt(num) - 1;
						$("#buyNum").val(num + "份");
					}
				} else {
					$("#wantBuy").val(proPrice);
				}
			});
			$("#increase").click(function() {
				var price = $("#wantBuy").val();
				price = parseInt(price);
				proPrice = parseInt(proPrice);
				$("#wantBuy").val(price + proPrice);
				num = parseInt(num) + 1;
				$("#buyNum").val(num + "份");
			});
		}
		
		$("#submit").click(function(){
			var proAmount = $("#wantBuy").val();
			var num = $("#buyNum").val().replace(/[^0-9]/ig, "");
			$.post("<%=basePath%>invest/getProKinds?proId=" + proId,function(result){
				proLeft = result.pro_left;
			});
			proLeft = proLeft - num;
			window.location.href="<%=basePath%>invest/orderPay?pramter="+proAmount+"?pramter="+proId+"?pramter="+proLeft;
		});
	});
</script>
</head>
<body>
	<div>
		<form id="order">
			<div>
				<span>产品名称</span> <span><input id="proName" disabled="true"></span>
			</div>
			<div>
				<span>当前收益</span> <span><input id="currentProfit"
					name="yearProfit" disabled="true"></span>
			</div>
			<div>
				<span>剩余份数（元）</span> <span><input id="leftNum" name="proLeft"
					disabled="true"></span>
			</div>
			<div>
				<span>我要购买（元）</span> <span><input id="wantBuy"
					name="proPrice" disabled="true"></span> <span> <input
					type="button" id="reduce" value="-" /> <input id="buyNum"
					disabled="true" style="text-align: center" /> <input
					type="button" id="increase" value="+" />
				</span>
			</div>
			<div>
				<span>投资时间</span> <span><input id="investTime"
					name="proCycle" disabled="true"></span>
			</div>
			<div>
				<span>还款方式</span> <span><input id="replyStyle"
					name="replyStyle" disabled="true"></span>
			</div>
		</form>
	</div>
	<div>
		<input id="submit" type="button" value="提交订单" />
		<input id="return" type="button" value="返回" onClick="history.back();"/>
	</div>
</body>
</html>